package com.xxx.generic;

import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/21 13:59
 * @Copyright 博为峰
 */
public class GenericDemo04 {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("张三", 20));
        it2(students);

        ArrayList<Worker> workers = new ArrayList<Worker>();
        workers.add(new Worker("lisi", 30));
//        it2(workers);

        ArrayList<String> strings = new ArrayList<>();
        strings.add("a");
//        it(strings);
    }

    //？ super E 接收E类型和E类型的父类型，下限
    private static void it2(ArrayList<? super Student> arrayList) {
        Iterator<?> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
        }
    }

    //？ extends E 接收E类型和E类型的子类型，上限
    private static void it(ArrayList<? extends Person> arrayList) {
        Iterator<?> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
        }
    }
}
